package com.demo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.Collections;

/**
 * FileName: SwaggerConfig
 *
 * @author: xunyong
 * Date:     2019/5/10 17:06
 * Description: SwaggerConfig
 */
@Configuration
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                /*根据基本包，类注释和方法注释过滤API 如:RequestHandlerSelectors.basePackage("org.baeldung.web.controller") */
                .apis(RequestHandlerSelectors.any())
                /*根据谓词来扫描应用程序的请求路径 如：paths(PathSelectors.ant("/foos/*") */
                .paths(PathSelectors.any())
                .build().apiInfo(apiInfo());
    }

    /**有关API的自定义信息*/
    private ApiInfo apiInfo() {
        return new ApiInfo(
                "My REST API",
                "Some custom description of API.",
                "API TOS",
                "Terms of service",
                new Contact("John Doe", "www.example.com", "myeaddress@company.com"),
                "License of API", "API license URL", Collections.emptyList());
    }

}